package com.kyh.controller.web.sys;

import javax.servlet.http.HttpServletRequest;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;

import com.kyh.service.sys.CommonService;
import com.kyh.sys.entity.Admin;
import com.kyh.util.ReqUtil;

/**
 * 网页控制器
 */
@Controller
public class WebSysController {
	
	private static final Logger logger = Logger.getLogger(WebSysController.class);
	
	@Autowired
	private CommonService commonService;

	/*
	 * 页面控制
	 */
    @GetMapping("/inter")
    public String inter(Model model,
    		HttpServletRequest request,
    		Long menuId,
    		Integer menuTypeTemplet
    		) {
    	
    	Long adminId = ReqUtil.getAdminId(request);
    	if (adminId.longValue() == 0) {
			return "login";
		}
    	
    	Long roleId = new Admin().setAdminid(adminId).queryFirst().getRoleId();
    	if (roleId.longValue() == 1L) {
			roleId = null;
		}
    	
    	return commonService.inter(model, request, menuId, menuTypeTemplet, roleId);
    }

	/*
	 * 页面控制（新增页）
	 */
    @GetMapping("/add")
    public String add(Model model,
    		HttpServletRequest request,
    		Long menuId
    		) {
    	return commonService.add(model, request, menuId);
    }

	/*
	 * 页面控制（编辑页）
	 */
    @GetMapping("/edit")
    public String edit(Model model,
    		HttpServletRequest request,
    		Long menuId,
    		Long valId,
    		Integer pageType // 页面类型，1普通页面2不带刷新的页面
    		) {

        return commonService.edit(model, request, menuId, valId, pageType);
    	
    }

	/**
	 * @param objId 对应的表单输入框ID
	 * 页面控制（选择器）
	 */
    @GetMapping("/selector")
    public String selector(Model model,
    		HttpServletRequest request,
    		Long colId,
    		String objId
    		) {
    	
    	return commonService.selector(model, request, colId, objId);
    	
    }

	/*
	 * 仪表盘
	 */
    @GetMapping("/dashboard")
    public String dashboard(Model model) {
    	
        return "dashboard";
    }

	/*
	 * 导入
	 */
    @GetMapping("/importExcel")
    public String importExcel(Model model,
    		HttpServletRequest request,
    		Long menuId
    		) {
    	
    	return commonService.importExcel(model, request, menuId);
    	
    }
}
